import React from 'react';
import check, { permissionCheck } from './CheckPermissions';

/**
 * @description
 * @param {*} { children:子组件, authority:路由权限, noMatch = null:权限不匹配渲染 }
 * @returns
 */
const Authorized = ({ children, authority, noMatch = null }) => {
  const childrenRender = typeof children === 'undefined' ? null : children;
  const dom = check(authority, childrenRender, noMatch);
  return <>{dom}</>;
};
// 暂时没用
const Permission = ({ children, authorKey, noMatch = null }) => {
  const childrenRender = typeof children === 'undefined' ? null : children;
  const dom = permissionCheck(authorKey, childrenRender, noMatch);
  return <>{dom}</>;
};

export default Authorized;
